/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ora_init_ora_packet.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/10 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include "../../test_ora_comm.h"
#include <oracle/ora_core.h>
#include <oracle/comm/ora_comm.h>
#include <oracle/tns/ora_packet.h>
#include <frct_comm.h>

extern void __ora_destroy_ora_packet(L7_ora_packet **pp_st_ora_packet);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    L7_ora_packet *p_st_ora_packet = NULL;
    p_st_ora_packet = (L7_ora_packet *) frmalloc(sizeof(L7_ora_packet));
    CU_ASSERT_PTR_NOT_NULL(p_st_ora_packet);
    memset(p_st_ora_packet, 0x00, sizeof(L7_ora_packet));

    CU_ASSERT_EQUAL(ora_init_ora_packet(p_st_ora_packet), FR_SUCC);

    CU_ASSERT_PTR_NOT_NULL(p_st_ora_packet->p_st_packet);
    CU_ASSERT_EQUAL(p_st_ora_packet->tns_type, APM_ORA_TNS_TYPE_UNSET);
    CU_ASSERT_EQUAL(p_st_ora_packet->ui_length_orig, 0);
    CU_ASSERT_EQUAL(p_st_ora_packet->ui_len_to_read, 0);
    CU_ASSERT_EQUAL(p_st_ora_packet->i_analyze_position, 0);
    CU_ASSERT_EQUAL(p_st_ora_packet->i_is_first_packet, FR_YES);
    CU_ASSERT_EQUAL(p_st_ora_packet->fragment_state, APM_ORA_FRAGMENT_INIT);
    CU_ASSERT_EQUAL(p_st_ora_packet->i_is_request, APM_ORA_FLAG_UNSET);
    CU_ASSERT_EQUAL(p_st_ora_packet->i_rpa_processed_flag, FR_NO);
    CU_ASSERT_EQUAL(p_st_ora_packet->i_rxh_processed_flag, FR_NO);
    CU_ASSERT_EQUAL(p_st_ora_packet->i_iov_processed_flag, FR_NO);
    CU_ASSERT_PTR_NULL(p_st_ora_packet->p_payload_left);
    CU_ASSERT_EQUAL(p_st_ora_packet->ui_payload_left_len, 0);
    CU_ASSERT_EQUAL(p_st_ora_packet->ul_skip_len, 0L);

    __ora_destroy_ora_packet(&p_st_ora_packet);
    CU_ASSERT_PTR_NULL(p_st_ora_packet);
}

int add_suite_ora_init_ora_packet(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ora_init_ora_packet()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
